package br.com.divulgaqui.service;

import javax.annotation.PostConstruct;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import br.com.divulgaqui.client.EnderecoServiceBeanLocal;
import br.com.divulgaqui.entity.Endereco;
import br.com.divulgaqui.persistence.dao.EnderecoDAO;
import br.com.divulgaqui.persistence.daoimpl.EnderecoDAOimpl;

@Stateless
public class EnderecoServiceBean implements EnderecoServiceBeanLocal {
	
	
	//injeta o entityManager
	@PersistenceContext(unitName="divulgaqui")
	private EntityManager entityManager;
	
	private EnderecoDAO enderecoDAO;
	
	
	/**
	 * Instancia o DAO após a classe ser criada.
	 */
	@PostConstruct
	void init(){
		enderecoDAO = new EnderecoDAOimpl(this.entityManager);
	}
	
	/**
	 * Salva endereço no banco de dados.
	 */
	@Override
	public void salvar(Endereco endereco) {
		enderecoDAO.salvar(endereco);
		
	}

}
